package com.dxy.dxythird.service.impl;

import com.dxy.dxythird.DO.ImageUrl;
import com.dxy.dxythird.repository.ImageUrlRepository;
import com.dxy.dxythird.service.ImageUrlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * junfeng 2018/11/1
 */
@Service
@Slf4j
public class ImageUrlServiceImpl implements ImageUrlService {

    @Autowired
    private ImageUrlRepository imageUrlRepository;

    /**
     * 图片链接地址保存
     *
     * @param url
     * @return
     */
    @Override
    public ImageUrl addImageUrl(String url) {
        ImageUrl imageUrl = new ImageUrl();
        imageUrl.setQiniuUrl(url);
        ImageUrl image = null;
        // 重复上传处理
        if (!imageUrlRepository.existsByQiniuUrl(url)) {
            image = imageUrlRepository.save(imageUrl);
        }
        return image;
    }
}
